package com.szqhyxj.youxiangju.biz.receivables;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * Created by leung on 2019/1/12.
 */

public class ReceivablesModel {
    interface receivablesService {
        @FormUrlEncoded
        @POST("wallet/withdraw/apply")
        Observable<BaseResult<ReceivablesBean>> receivables(
                @Field("withdrawAmt") String withdrawAmt,
                @Field("bankCardNo") String bankCardNo,
                @Field("btCode") String btCode,
                @Field("btName") String btName,
                @Field("phone") String phone,
                @Field("code") String code
        );

        @POST("online/cash/querySupportBank")
        Observable<BaseResult<List<Response>>> supportBank();

        @FormUrlEncoded
        @POST("msg/sms/cashWithdrawal")
        Observable<BaseResult> realNameSms(@Field("phone") String phone);

    }

    public static Observable<BaseResult<ReceivablesBean>> getReceivables(Receivables receivables) {
        return RetrofitFacade.Companion.getRetrofit().create(receivablesService.class).receivables(
                receivables.getWithdrawAmt(),
                receivables.getBankCardNo(),
                receivables.getBtCode(),
                receivables.getBtName(),
                receivables.getPhone(),
                receivables.getCode()
        );
    }

    public static Observable<BaseResult<List<Response>>> getSupportBank(){
        return RetrofitFacade.Companion.getRetrofit().create(receivablesService.class).supportBank();
    }
    public static Observable<BaseResult> realNameSms(String phone){
        return RetrofitFacade.Companion.getRetrofit()
                .create(receivablesService.class)
                .realNameSms(
                        phone
                );
    }



    public static class ReceivablesBean {

        @SerializedName("withdrawId")
        private String withdrawId;

        public void setWithdrawId(String withdrawId) {
            this.withdrawId = withdrawId;
        }

        public String getWithdrawId() {
            return withdrawId;
        }

        @Override
        public String toString() {
            return
                    "ReceivablesBean{" +
                            "withdrawId = '" + withdrawId + '\'' +
                            "}";
        }
    }

    public static class Receivables{

        @SerializedName("btCode")
        private String btCode;

        @SerializedName("code")
        private String code;

        @SerializedName("bankCardNo")
        private String bankCardNo;

        @SerializedName("phone")
        private String phone;

        @SerializedName("withdrawAmt")
        private String withdrawAmt;

        @SerializedName("btName")
        private String btName;

        public void setBtCode(String btCode){
            this.btCode = btCode;
        }

        public String getBtCode(){
            return btCode;
        }

        public void setCode(String code){
            this.code = code;
        }

        public String getCode(){
            return code;
        }

        public void setBankCardNo(String bankCardNo){
            this.bankCardNo = bankCardNo;
        }

        public String getBankCardNo(){
            return bankCardNo;
        }

        public void setPhone(String phone){
            this.phone = phone;
        }

        public String getPhone(){
            return phone;
        }

        public void setWithdrawAmt(String withdrawAmt){
            this.withdrawAmt = withdrawAmt;
        }

        public String getWithdrawAmt(){
            return withdrawAmt;
        }

        public void setBtName(String btName){
            this.btName = btName;
        }

        public String getBtName(){
            return btName;
        }
        public boolean valid () {

            return !TextUtils.isEmpty(this.withdrawAmt)
                    &&!TextUtils.isEmpty(this.bankCardNo)
                    && !TextUtils.isEmpty(this.btCode)
                    && !TextUtils.isEmpty(this.btName)
                    && !TextUtils.isEmpty(this.phone)
                    && !TextUtils.isEmpty(this.code)
                    ;

        }
        @Override
        public String toString(){
            return
                    "ReceivablesBean{" +
                            "btCode = '" + btCode + '\'' +
                            ",code = '" + code + '\'' +
                            ",bankCardNo = '" + bankCardNo + '\'' +
                            ",phone = '" + phone + '\'' +
                            ",withdrawAmt = '" + withdrawAmt + '\'' +
                            ",btName = '" + btName + '\'' +
                            "}";
        }
    }

    public static class Response{

        @SerializedName("btCode")
        private String btCode;

        @SerializedName("bankName")
        private String bankName;

        public void setBtCode(String btCode){
            this.btCode = btCode;
        }

        public String getBtCode(){
            return btCode;
        }

        public void setBankName(String bankName){
            this.bankName = bankName;
        }

        public String getBankName(){
            return bankName;
        }

        @Override
        public String toString(){
            return
                    "Response{" +
                            "btCode = '" + btCode + '\'' +
                            ",bankName = '" + bankName + '\'' +
                            "}";
        }
    }
}
